package sopia.cmm;

import sopia.conn.CustomerSpinnerAdapter;
import android.database.Cursor;
import android.widget.ArrayAdapter;
public class CommonFunct {

	public static boolean  isNullOrEmpty(String str){
		if(str == null || (str!= null 
				&& Constant.EMPTY_STRING.equals(str))){
			return true;
		}
		return false;
	}
	public static String join(String... strInput) {
		StringBuilder sb = new StringBuilder();
		for (String str : strInput) {
			sb.append(nvl(str));
		}
		return sb.toString();
	}
	private static String nvl(String sIn) {
		return (sIn == null) ? "" : sIn;
	}
	public static CustomerSpinnerAdapter[] getSpinnerAdapter(Cursor cur) {
		
			final CustomerSpinnerAdapter items[] = new CustomerSpinnerAdapter[cur.getCount()];
			int i = 0;
			if (cur.moveToFirst()) {
		         do {
		        	 String id = cur.getString(0);
//		        	 String value = cur.getString(1);
		        	 items[i++] = new CustomerSpinnerAdapter(id, id);
		         } while (cur.moveToNext());
		      }
		      if (cur != null && !cur.isClosed()) {
		    	  cur.close();
		      }
			return items;
	}
	public static String[] removeHash(String str){
		return str.split(Constant.HASH_STRING);
	}
	public static int getIndexFromElement(ArrayAdapter<CustomerSpinnerAdapter> adapter, String element) {
		      for(int i = 0; i < adapter.getCount(); i++) {
		            if(adapter.getItem(i).getValue().equals(element)) {
		                  return i;
		            }
		      }
		      return 0;
		}
}
